package at.technikum.fotoalbum.utils;

import java.util.Vector;

import javax.faces.context.FacesContext;

public class Utils {

	public static Object getManagedBean(String bean) {
		FacesContext fc = FacesContext.getCurrentInstance();
		return fc.getApplication().getELResolver()
				.getValue(fc.getELContext(), null, bean);
	}

	public static String[] mixUpArray(String inarray[]) {
		// get the size of the array
		int iSize = inarray.length;
		// create an array the same size as the input array
		String outarray[] = new String[iSize];
		// Convert the array to a Vector
		Vector<String> temparray = new Vector<String>();
		// Copy the array to the Vector
		for (int i = 0; i < iSize; i++)
			temparray.add(inarray[i]);
		// perform the mix up
		for (int i = 0; i < iSize; i++) {
			// Choose a random Vector item
			int vSize = temparray.size();
			int iRandom = (int) (Math.random() * vSize);
			// store the chosen vector item in the array
			outarray[i] = temparray.get(iRandom);
			// remove the item from the vector
			temparray.remove(iRandom);
		}
		// return the new array
		return outarray;
	} // method MixUpArray

}
